<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>创客手机网站</title>
  <script src="/wap/js/flexible.js"></script>
  <script src="/wap/js/jquery-3.2.1.min.js"></script>
  <script src="/wap/js/util.js"></script>
  <link rel="stylesheet" href="/wap/css/style.css">
  <style>
    html, body {
      height: 100%;
    }
  </style>
</head>
<body>
  <div id="widthdraw">
    <div class="widthdraw__form">
      <input type="hidden" name="_token" value="{{csrf_token()}}">
      <div class="form__input">
        <div class="input__user input" style="position: relative" onclick="location.href='/wap/index/bankAccountList/{{ $id }}'">
          <div class="input__left">银行卡</div>
          <div class="input__right">
            @if($bankInfo)
              <input type="hidden" name="wx_id" value="{{ $bankInfo['id'] }}">
              <input type="text" id="card_name" value="{{ $bankInfo['bank']['bank_name'].substr_replace($bankInfo['account_code'],str_repeat('X',strlen($bankInfo['account_code'])-8),4,-4) }}" disabled style="margin-right: 0.4rem;">
            @else
              <input type="text" placeholder="选择银行卡" id="card_name" value="" disabled style="margin-right: 0.4rem;">
            @endif
            <img src="/wap/image/arrow_gray.png" class="arrow">
          </div>
        </div>
        <div class="input__user input">
          <div class="input__left">登录密码</div>
          <div class="input__right">
            <input type="password" id="login_pwd" name="password" placeholder="请输入登录密码">
          </div>
        </div>
        <div class="input__points input">
          <div class="input__left">积分</div>
          <div class="input__right">
            <input type="text" name="cash" id="point_num" placeholder="请输入提现的积分"/>
          </div>
        </div>
      </div>
      <div class="form__info">
        <p class="form__info__detail">当前积分余额<span id="allIntegral">{{ $data->integral }}</span><span class="all__btn" onclick="withAll()">全部提现</span></p>
      </div>
      <div class="form__btn">完成</div>
      <p style="font-size: 0.4rem;color: #333;padding: 0.4rem;margin-top: 0.4rem">提现说明</p>
      <p style="font-size: 0.4rem;color: #666;padding: 0.1rem 0.4rem 0;">1.创客个人账户上的积分可提现，也可用于购物。</p>
      <p style="font-size: 0.4rem;color: #666;padding: 0.1rem 0.4rem 0;">2.每次提现金额至少为100，或100的整数倍。</p>
      <p style="font-size: 0.4rem;color: #666;padding: 0.1rem 0.4rem 0;">3.提现需要先完善收款银行信息，要求为个人名下银行信息。</p>
      <p style="font-size: 0.4rem;color: #666;padding: 0.1rem 0.4rem 0;"> 4.提交提现申请后，会在5-7个工作日到账。</p>
    </div>
  </div>
</body>
</html>

<script>
    $(function(){
        $('input').bind('input propertychange', function() {
            var isTrue = $('#card_name').val()!='' &&  $('#point_num').val()!='' &&  $('#login_pwd').val()!=''?true:false;
            console.log(isTrue);
            if(isTrue)
                $('.form__btn').addClass('bg-e60012');
            else
                $('.form__btn').removeClass('bg-e60012');
        });
    })
  function withAll() {
      var cash = $('#allIntegral').html();
      $('input[name="cash"]').val(cash);
  }
  $('.form__btn').on('click', function() {
      var wx_id = $('input[name="wx_id"]').val();
      var password = $('input[name="password"]').val();
      var cash = $('input[name="cash"]').val();
      var csrf_token = $('input[name="_token"]').val();
      if(wx_id == ''){
          toast('未选择银行卡！',2000);
          $('input[name="wx_id"]').focus();
          return false;
      }
      if(cash == '' || cash < 100 || cash%100!=0){
          toast('未输入提现积分或额度不是100的整数倍！',2000);
          $('input[name="cash"]').focus();
          return false;
      }
      $.ajax({
          type: 'post',
          url: '{{ route('wap.index.ajaxWithdraw') }}',
          data: {'wx_id':wx_id,'password':password,'cash':cash,'_token':csrf_token,'user_id':'{{ $data->id }}'},
          dataType: "JSON",
          async: false,
          success: function (res) {
              console.log(res);
              if(res.status=='FAIL'){
                  toast(res.message,2000);
              }else{
                  ZAlert('提现成功', '您的提现申请已成功提交，我们将尽快审核处理！！',res.url);
              }
          },
          error: function (res) {
              console.log(res, 'error');
          }
      });
  })

</script>